//
//  SocketManager.h
//  Demo
//
//  Created by xiu on 2020/4/22.
//  Copyright © 2020 111. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SRWebSocket.h"

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger,WebSocketConnectType){
    WebSocketDefault = 0,  //初始状态,未连接
    WebSocketRequest,      //请求中
    WebSocketConnect,      //已连接
    WebSocketDisconnect    //连接后断开
};

@class SocketManager;

@protocol SocketManagerDelegate <NSObject>
/**
* 数据回调
*/
- (void)SocketManagerDidReceiveMessageWithString:(NSString *_Nullable)string;
@end

@interface SocketManager : NSObject
@property(nonatomic,strong)SRWebSocket *webSocket;
@property(nonatomic,weak) id<SocketManagerDelegate>delegate;
@property(nonatomic,assign) BOOL isConnect;//是否连接
@property(nonatomic,assign)WebSocketConnectType connectType;
@property(nonatomic,strong)NSString *getserverAndPort;
/**
* 单例
*/
+ (instancetype)shared;
/**
* 建立长连接
*/
- (void)connectServer;
/**
* 重新连接
*/
- (void)reConnectServer;//重新连接
/**
* 关闭长连接
*/
- (void)WebSocketClose;
/**
* 发送数据给服务器
*/
- (void)sendDataToServer:(NSString *)data;
@end

NS_ASSUME_NONNULL_END
